<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet" />
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}" />
    <link rel="stylesheet" th:href="@{/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css}" type="text/css">
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}" />
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet" />
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}" />
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}" />
    <link th:href="@{/erp/Widget/icheck/icheck.css}" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="type_style">

    <div class="type_title">部门信息</div>
    <div class="type_content">
        <span id="spans1" style="display:block">
		<div class="Operate_btn">  <a href="javascript:;" onClick="xinzeng()" class="btn  btn-warning"><i class="icon-plus align-top bigger-125"></i>新增下级部门</a> <a href="javascript:ovid()" id="shanchu" class="btn  btn-danger"><i class="icon-trash   align-top bigger-125"></i>删除该部门</a> </div>

			<form action="/dept/deptHighAdd" method="post" class="form form-horizontal" id="form-user-add" onsubmit="return checkInput()">
				  <ul class=" page-content">
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>部门编号：</label>
			  <div class="formControls " style="width:280px;">
				 <input type="text" class="input-text" name="id" id="id" onblur="isDeptId()">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>部门名称：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" placeholder="部门名称" id="deptName" onblur="isDeptName()"  name="deptName">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>部门经理：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" placeholder="部门经理" id="deptManger"  name="deptManger">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>联系电话：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" placeholder="联系电话" id="deptTel" onblur="isTel()"  name="deptTel">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red"></span>固定电话：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" placeholder="固定电话" id="deptPhone" onblur="isPhone()"  name="deptPhone"><br>
                  <span style="color: red;">格式为区号+电话号码。000-0000000</span>
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red"></span>邮箱：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" placeholder="邮箱" id="deptEmail" onblur="isEmail()"   name="deptEmail">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red"></span>部门职位：</label>
			  <div class="formControls " id="test2">
				<input type="text" class="input-text" placeholder="部门职位" id="postName"  name="postName"><br/><br/>
			  </div>
			</div>

			<div class="Operate_cont clearfix">
			  <label class="form-label">部门简介：</label>
			  <div class="formControls">
				<textarea name="deptRemark" rows="" class="textarea"  placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="textarealength(this,100)">这个部门很好</textarea>

			  </div>
			</div>
		  </ul>
		<div class="">
            <div class="" style=" text-align:center">
              <input class="btn btn-primary radius" type="submit" value="保存">
			  <input class="btn btn-primary radius" type="reset" value="取消">
            </div>
          </div>
        </form></span>
    </div>
</div>
<script type="text/javascript">
	function isTel(){
		var s =$("#deptTel").val();
		if(!(/^1[3456789]\d{9}$/.test(s))){
            parent.layer.msg("联系电话有误，请重填", {icon: 2});
			return false;
		}
	}
	function isPhone(){
		var s =$("#deptPhone").val();
		if(!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,8}$/.test(s)){
			parent.layer.msg("固定电话有误", {icon: 2});
			return false;
		}
	}
	
	function isEmail() {
		var s =$("#deptEmail").val();
		if(!/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/.test(s)){
            parent.layer.msg("邮箱有误，请重填", {icon: 2});
			return false;
		}
	}
	
	function isDeptName() {
        var deptName = $("#deptName").val();
        $.ajax({
            type:"get",
            url:"/dept/isDeptName",
            data:{"deptName":deptName},
            success:function (res) {
                if (res.rs) {

                } else {
                    layer.msg("部门名称已存在", {icon: 2});
                }
            }
        })
    }

    function isDeptId() {
        var deptId = $("#id").val();
		//&lt;![CDATA[
		var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
		//]]>
		if (reg.test(deptId)){
			layer.msg("请输入英文或者数字", {icon: 2});
		}else{
        $.ajax({
            type:"get",
            url:"/dept/isDeptId",
            data:{"deptId":deptId},
            success:function (res) {
                if (res.rs) {

                } else {
                    layer.msg("部门编号已存在", {icon: 2});
                }
            }
        })
		}
    }

function checkInput() {
	var flag  =false;
var deptId = $("#id").val();
if(deptId == ""){
	parent.layer.msg("部门编号不能为空", {icon: 2});
	return false;
}else if($("#deptName").val() == ""){
	parent.layer.msg("部门名称不能为空", {icon: 2});
	return false;
}else if($("#deptManger").val() == ""){
	parent.layer.msg("部门经理不能为空", {icon: 2});
	return false;
}else if($("#deptTel").val() == ""){
	parent.layer.msg("联系电话不能为空", {icon: 2});

	return false;
}else if($("#deptPhone").val() == ""){
	parent.layer.msg("固定电话不能为空", {icon: 2});
	return false;
}else if($("#deptEmail").val() == ""){
	parent.layer.msg("邮箱不能为空", {icon: 2});
	return false;
}else if($("#postName").val() == ""){
	parent.layer.msg("部门职位不能为空", {icon: 2});
	return false;
}else{
	var deptTel =$("#deptTel").val();
	var deptPhone =$("#deptPhone").val();
	var deptEmail =$("#deptEmail").val();
	var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
	if((!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,8}$/.test(deptPhone))){
		parent.layer.msg("固定电话有误，请重填", {icon: 2});
		return false;
	}else if(!/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/.test(deptEmail))
	{
		parent.layer.msg("邮箱有误，请重填", {icon: 2});
		return false;
	}else if(!(/^1[3456789]\d{9}$/.test(deptTel))){
		parent.layer.msg("联系电话有误，请重填", {icon: 2});
		return false;
	}else if(reg.test(deptId)){
		layer.msg("请输入英文或者数字", {icon: 2});
		return false;
	}{
		flag = true;
	}
}
return flag;
}

	function xinzeng(){
		var id = $("#id").val();
		var deptId = $("#updId").val();
		if(id == ""){
			parent.layer.msg("清先选择上级部门", {icon: 2});
		}else {
			$("#idss").val(deptId);
			document.getElementById("shanchu").style.display = "none";
			document.getElementById("spans1").style.display = "none";
			document.getElementById("spans2").style.display = "block";
		}
	}

</script>
</body>
</html>